set nocompatible              " be iMproved, required
set nocp
set shiftwidth=4
set tabstop=4
set softtabstop=4
""set autoindent
set fileencodings=UTF-8,GBK
set termencoding=UTF-8
set encoding=UTF-8
set nu
set ru
"set hls
set is
filetype off                  " required

"filetype plugin on
set t_Co=256
"set background=light
set background=dark

colorscheme jmdkina
" colorscheme vim-monokai-tasty
" colorscheme dank-neon
set cursorline
hi cursorline    cterm=NONE ctermbg=233

set incsearch
set hlsearch

call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-master branch
"Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'

Plug 'patstockwell/vim-monokai-tasty'

Plug 'Valloric/YouCompleteMe'

" Initialize plugin system
call plug#end()

"why can't use backspace
set backspace=indent,eol,start
set statusline=%F\ \ \~\~\~\~\ \ \V:\ %04l\/%04L(%p%%),\ H:\ %03v
set laststatus=2

set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

nnoremap <silent> <F8> :TlistToggle<CR>
let Tlist_Exit_OnlyWindow = 1

set tags+=~/.vim/tags/cpp_src/tags

map <C-n> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let g:NERDTreeIndicatorMapCustom = {
	    \ "Modified"  : "✹",
	    \ "Staged"    : "✚",
	    \ "Untracked" : "✭",
	    \ "Renamed"   : "➜",
	    \ "Unmerged"  : "═",
	    \ "Deleted"   : "✖",
	    \ "Dirty"     : "✗",
	    \ "Clean"     : "✔︎",
        \ 'Ignored'   : '☒',
	    \ "Unknown"   : "?"
	    \ }

"Bundle 'rdnetto/YCM-Generator'
"Bundle 'Valloric/YouCompleteMe'

"nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
"nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
"nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>

:nnoremap <F5> "=strftime("%c")<CR>
:inoremap <F5> <C-R>=strftime("%c")<CR>

autocmd BufNewFile *.cpp,*.[ch] exec ":call SetHeader()"
autocmd BufNewFile *.py exec ":call SetPYHeader()"

func SetPYHeader()
	call setline(1, "# coding=utf-8")
	call append(line("."), "")
	call append(line("."), "##")
	call append(line("."), "## Create: ".strftime("%c"))
	call append(line("."), "##")
	call append(line("."), "## Author: jmdvirus@aliyun.com")
	call append(line("."), "##")

	autocmd BufNewFile * normal G
endfunc

func SetHeader()
	call setline(1, "/*********************************************************")
	call append(line("."), " *")
	call append(line(".") + 1, " *   @file: ".expand("%"))
	call append(line(".") + 2, " * @author: jmdvirus")
	call append(line(".") + 3, " *   @date: ".strftime("%c"))
	call append(line(".") + 4, " *")
	call append(line(".") + 5, " *********************************************************/")
	call append(line(".") + 6, "")
	if &filetype == 'cpp'
		call append(line(".") + 7, "#include <iostream>")
		call append(line(".") + 8, "")
	endif
	if &filetype == 'c'
		call append(line(".") + 7, "#include <stdio.h>")
		call append(line(".") + 8, "")
	endif
	if &filetype == "py"
		call append(line(".") + 7, "# coding=utf-8")
		call append(line(".") + 8, "")
	endif

	autocmd BufNewFile * normal G
endfunc

